package com.zb.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zb.entity.Car;
import com.zb.entity.Help;
import com.zb.entity.Msi;
import com.zb.entity.Store;
import com.zb.service.CarService;
import com.zb.service.HelpService;
import com.zb.service.MsiService;
import com.zb.service.StoreService;
import com.zb.service.impl.CarServiceImpl;
import com.zb.service.impl.HelpServiceImpl;
import com.zb.service.impl.MsiServiceImpl;
import com.zb.service.impl.StoreServiceImpl;

/**
 * Servlet implementation class HelpServlet
 */
public class HelpServlet extends HttpServlet {
	private StoreService stor=new StoreServiceImpl();
	private CarService car=new CarServiceImpl();
	private HelpService help=new HelpServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		String op=request.getParameter("op");
		if(op.equals("msi")) {
			this.store(request, response);
		}else if(op.equals("jyby")) {
			this.jyby(request, response);
		}
		
	}
	protected void store(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		List<Store> store=stor.getAllStore();
		request.setAttribute("s",store);
		request.getRequestDispatcher("jyby.jsp").forward(request, response);
	}
	protected void jyby(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String carNum=request.getParameter("carNum");
		String carName=request.getParameter("carName");
		String carAir=request.getParameter("carAir");
		Car c=new Car();
		c.setCarAir(carAir);
		c.setCarName(carName);
		c.setCarNum(carNum);
		car.addCar(c);
		
		int max=car.getMax();
		String place=request.getParameter("place");
		int store=Integer.parseInt(request.getParameter("store"));
		
		Help h=new Help();
		h.setCar(max);
		Store s=new Store();
		s.setId(store);
		h.setStore(s);
		h.setPlace(place);
		help.addHelp(h);
	}

}
